import DrawRectangle  from './draw/DrawRectangle';
import DrawPoint from "./draw/DrawPoint"
import DrawPolyline from './draw/DrawPolyline';
import DrawPolygon from './draw/DrawPolygon';
import DrawCircle from './draw/DrawCircle';

/**
 * 绘制工具
 */
export default class DrawTool {
    /**
     * 构造函数
     * @param viewer
     */
    constructor(viewer) {
        this.viewer = viewer;
        this.drawPoint = null;
        this.drawRectangleTool = null;
        this.drawPolyline = null;
        this.drawPolygon = null;
        this.drawCircle = null;
    }
 
    /**
     * 激活点线面
     * @param drawType
     */
    activate(drawType, callback) {
        this.clearAll();
        switch (drawType) {
            case 'Point': {
                this.drawPoint = new DrawPoint(this.viewer)
                this.drawPoint.activate(callback)
                break;
            }
            case 'Polyline': {
                this.drawPolyline = new DrawPolyline(this.viewer)
                this.drawPolyline.activate(callback)
                break;
            }
            case 'Polygon': {
                this.drawPolygon = new DrawPolygon(this.viewer)
                this.drawPolygon.activate(drawType, callback)
                break;
            }
            case 'Rectangle': {
                this.drawRectangleTool = new DrawRectangle(this.viewer)
                this.drawRectangleTool.activate(callback)
                break;
            }
            case 'Circle':
                this.drawCircle = new DrawCircle(this.viewer)
                this.drawCircle.activate(callback)
                break;
        }
    }
 
    /**
     * 清除
     */
    clearAll() { 
        this.drawPoint && this.drawPoint.clearAll()
        this.drawPolyline && this.drawPolyline.clearAll()
        this.drawRectangleTool && this.drawRectangleTool.clearAll()
        this.drawPolygon && this.drawPolygon.clearAll()
        this.drawCircle && this.drawCircle.clearAll()
    }
    
}
